/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.g;

import android.content.Context;
import android.content.Intent;
import com.qihoo.gamecenter.sdk.login.plugin.h.d;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.login.c;
import org.json.JSONException;
import org.json.JSONObject;

public class h extends k {
    private c d;
    private com.qihoo.a.a.a e;

    public h(Context paramContext, Intent paramIntent, c paramc, com.qihoo.a.a.a parama) {
        super(paramContext, paramIntent);
        this.d = paramc;
        this.e = parama;
    }

    protected String a(String[] paramArrayOfString) {
        String str1 = null;
        if (this.e != null) {
            String str2 = this.b.getPackageName();
            String str3 = this.d.b();
            String str4 = com.qihoo.gamecenter.sdk.login.plugin.h.a.a(this.b, this.c);
            int i = com.qihoo.gamecenter.sdk.common.a.a.a(str3);
            String str5 = com.qihoo.gamecenter.sdk.login.plugin.a.h.a(this.b, this.d, this.c);
            String str6 = null;
            String[] arrayOfString = new String[2];
            try {
                int j = this.e.b(str2, str3, str4, i, str5, str6, arrayOfString);
                e.a("Plugin.LoginByServiceTask", new Object[] { "result[0]="
                        + ((arrayOfString[0] != null) ? arrayOfString[0] : "null") });
                e.a("Plugin.LoginByServiceTask", new Object[] { "result[1]="
                        + ((arrayOfString[1] != null) ? arrayOfString[1] : "null") });
                String str7 = arrayOfString[1];
                if ((j != 0) && (j != 5099) && (j != 99102))
                    com.qihoo.gamecenter.sdk.login.plugin.h.h.a(this.b, String.valueOf(j), str5, str7, true);
                a(this.b, str7);
                e.a("Plugin.LoginByServiceTask", new Object[] { "errno:" + j });
                String str8 = a(j, str7);
                str1 = str8.toString();
            } catch (Exception localException) {
                e.b("Plugin.LoginByServiceTask", "", localException);
            }
        }
        return str1;
    }

    private boolean a(Context paramContext, String paramString) {
        int i = 0;
        try {
            JSONObject localJSONObject = new JSONObject(paramString);
            if (localJSONObject != null) {
                String str;
                if (localJSONObject.has("qt")) {
                    str = localJSONObject.getString("qt");
                    d.a(str, ";");
                    i = 1;
                }
                if (localJSONObject.has("qid")) {
                    str = localJSONObject.getString("qid");
                    d.a(paramContext, str);
                }
            }
        } catch (JSONException localJSONException) {
            e.b("Plugin.LoginByServiceTask", "", localJSONException);
        }
        return i;
    }

    private String a(int paramInt, String paramString) {
        e.a("Plugin.LoginByServiceTask", new Object[] { paramString });
        JSONObject localJSONObject1 = new JSONObject();
        try {
            localJSONObject1.put("errno", paramInt);
            if (paramInt == 0) {
                JSONObject localJSONObject2 = new JSONObject();
                JSONObject localJSONObject3 = new JSONObject(paramString);
                String str2 = localJSONObject3.optString("auth_code", "");
                localJSONObject2.put("code", str2);
                String str3 = localJSONObject3.optString("state", "");
                localJSONObject2.put("state", str3);
                JSONObject localJSONObject4 = localJSONObject3.optJSONObject("fields");
                if (localJSONObject4 == null) {
                    localJSONObject4 = new JSONObject();
                    String str4 = localJSONObject3.optString("qid");
                    if (str4 != null)
                        localJSONObject4.put("qid", str4);
                }
                localJSONObject1.put("user", localJSONObject4);
                localJSONObject1.put("data", localJSONObject2);
            }
        } catch (JSONException localJSONException) {
            e.b("Plugin.LoginByServiceTask", "", localJSONException);
        }
        String str1 = localJSONObject1.toString();
        e.a("Plugin.LoginByServiceTask", new Object[] { "convertJsonString: " + str1 });
        return str1;
    }
}